<?php
namespace Admin\Controller;
use Think\Controller;
class AdminController extends Controller {
	
	//管理员首页
    public function index(){
    	//实例化数据库
    	$model = M('admin');
    	//查询总数据
    	$total = $model->count();
    	
    	//实例化分页
    	$page = new \Think\Page($total,1);
    	
    	//获取当前页
    	$p = isset($_GET['p'])?$_GET['p']:1;
    	
    	$this->data = $model->order('id desc')->page($p.',1')->select();
    	
    	//分页
    	$this->page = $page->show();
    	$this->total = $total;
    	$this->display();
    }
    
    //管理员首页
    public function add(){
    	if(IS_POST){
    		//实例化数据模型
    		$model = D('admin');
    		
    		$model->create();
    		$model->time = time();
    		$model->status = 0;
    		$model->password = md5($_POST['password']);
    		
    		if($model->add()){
    			$this->success('添加成功',U("Index"));
    		}else{
    			$this->error('添加失败');
    		}
    	}else{
    		$this->display();
    	} 
    }
}